﻿using System;

using RoughJs.Ast;

namespace RoughJs.Error
{
    public class EcmaError : RhinoException
    {
        private String errorName;
        private String errorMessage;

        public EcmaError(String errorName, String errorMessage,
              String sourceName, int lineNumber,
              String lineSource, int columnNumber)
        {
            recordErrorOrigin(sourceName, lineNumber, lineSource, columnNumber);
            this.errorName = errorName;
            this.errorMessage = errorMessage;
        }

        /**
         * @deprecated EcmaError error instances should not be constructed
         *             explicitly since they are generated by the engine.
         */
        public EcmaError(Scriptable nativeError, String sourceName,
                         int lineNumber, int columnNumber, String lineSource)
            : this("InternalError", ScriptRuntime.toString(nativeError),
                sourceName, lineNumber, lineSource, columnNumber)
        {

        }


        public String details()
        {
            return errorName + ": " + errorMessage;
        }

        /**
         * Gets the name of the error.
         *
         * ECMA edition 3 defines the following
         * errors: EvalError, RangeError, ReferenceError,
         * SyntaxError, TypeError, and URIError. Additional error names
         * may be added in the future.
         *
         * See ECMA edition 3, 15.11.7.9.
         *
         * @return the name of the error.
         */
        public String getName()
        {
            return errorName;
        }

        /**
         * Gets the message corresponding to the error.
         *
         * See ECMA edition 3, 15.11.7.10.
         *
         * @return an implementation-defined string describing the error.
         */
        public String getErrorMessage()
        {
            return errorMessage;
        }

        /**
         * @deprecated Use {@link RhinoException#sourceName()} from the super class.
         */
        public String getSourceName()
        {
            return sourceName();
        }

        /**
         * @deprecated Use {@link RhinoException#lineNumber()} from the super class.
         */
        public int getLineNumber()
        {
            return lineNumber();
        }

        /**
         * @deprecated
         * Use {@link RhinoException#columnNumber()} from the super class.
         */
        public int getColumnNumber()
        {
            return columnNumber();
        }

        /**
         * @deprecated Use {@link RhinoException#lineSource()} from the super class.
         */
        public String getLineSource()
        {
            return lineSource();
        }

        /**
         * @deprecated
         * Always returns <b>null</b>.
         */
        public Scriptable getErrorObject()
        {
            return null;
        }
    }
}
